<template>
    <div>
        <el-row>
            <el-form :inline="true" :model="formInline" class="demo-form-inline">
                <el-form-item label="用户名称">
                    <el-input v-model="formInline.memberName" placeholder="输入用户名称"></el-input>
                </el-form-item>
                <el-form-item label="车辆名称">
                    <el-input v-model="formInline.carName" placeholder="输入车辆名称"></el-input>
                </el-form-item>
                <el-form-item label="开始日期">
                    <div>
                    <el-date-picker
                            v-model="formInline.startTime"
                            align="right"
                            type="date"
                            placeholder="选择日期"
                            :picker-options="pickerOptions" value-format="yyyy-MM-dd" format="yyyy-MM-dd">
                    </el-date-picker>
                    </div>
                </el-form-item>

                <el-form-item label="结束日期">
                    <el-date-picker
                            v-model="formInline.endTime"
                            align="right"
                            type="date"
                            placeholder="选择日期"
                            :picker-options="pickerOptions" value-format="yyyy-MM-dd" format="yyyy-MM-dd">
                    </el-date-picker>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="onSubmit">搜索</el-button>
                </el-form-item>
            </el-form>
        </el-row>
        <el-row>
            <el-table
                    :data="tableData"
                    style="width: 100%">
                <el-table-column
                        prop="orderNo"
                        label="订单编号">
                </el-table-column>
                <el-table-column
                        prop="memberName"
                        label="用户名">
                </el-table-column>
                <el-table-column
                        prop="carName"
                        label="车辆名称">
                </el-table-column>
                <el-table-column
                        prop="vin"
                        label="车牌号">
                </el-table-column>
                <el-table-column
                        prop="startTime"
                        label="下单时间">
                </el-table-column>
                <el-table-column
                        prop="endTime"
                        label="还车时间">
                </el-table-column>
                <el-table-column prop="state" label="订单状态">
                    <template slot-scope="scope">
                        <span v-if="scope.row.state === 1"><el-button size="mini" >输入</el-button></span>
                        <span v-if="scope.row.state === 2"><el-button size="mini" type="primary">提交</el-button></span>
                        <span v-if="scope.row.state === 3"><el-button size="mini" type="warning">预约</el-button></span>
                        <span v-if="scope.row.state === 4"><el-button size="mini" type="info">使用中</el-button></span>
                        <span v-if="scope.row.state === 5"><el-button size="mini" type="success">交还</el-button></span>
                        <span v-if="scope.row.state === 6"><el-button size="mini" type="danger">取消</el-button></span>
                    </template>
                </el-table-column>
                <el-table-column
                        prop="totalPrice"
                        label="总金额">
                </el-table-column>

                <el-table-column label="操作" width="180">
                    <template slot-scope="scope">
                        <el-button
                                size="mini"
                                @click="handleEdit(scope.$index, scope.row)">还车
                        </el-button>
                        <el-button
                                size="mini"
                                type="danger"
                                @click="handleDelete(scope.$index, scope.row)">删除
                        </el-button>
                    </template>
                </el-table-column>
            </el-table>
        </el-row>
        <el-row>
            <el-pagination
                    @size-change="handleSizeChange"
                    @current-change="handleCurrentChange"
                    :current-page="currentPage"
                    :page-sizes="[2,3,5,10]"
                    :page-size="pageSize"
                    layout="total, sizes, prev, pager, next, jumper"
                    :total="total">
            </el-pagination>
        </el-row>
    </div>
</template>

<script>
    export default {
        data() {
            return {
                pickerOptions: {
                    disabledDate(time) {
                        return time.getTime() > Date.now();
                    },
                    shortcuts: [{
                        text: '今天',
                        onClick(picker) {
                            picker.$emit('pick', new Date());
                        }
                    }, {
                        text: '昨天',
                        onClick(picker) {
                            const date = new Date();
                            date.setTime(date.getTime() - 3600 * 1000 * 24);
                            picker.$emit('pick', date);
                        }
                    }, {
                        text: '一周前',
                        onClick(picker) {
                            const date = new Date();
                            date.setTime(date.getTime() - 3600 * 1000 * 24 * 7);
                            picker.$emit('pick', date);
                        }
                    }]
                },
                tableData: [],
                sex: '',
                level: '',
                status: '',
                currentPage: 1,
                total: 100,
                formInline: {memberName: ``, carName: ``,startTime:``,endTime:``},
                pageSize: 5,
                dialogVisible: false,
                value1: '',
                value2: '',
                rules: {
                    username: [{required: true, message: '会员名称不能为空', trigger: 'blur'}],
                    phoneNum: [{required: true, message: '手机号不能为空', trigger: 'blur'}],
                    address: [{required: true, message: '地址不能为空', trigger: 'blur'}],
                    email: [{required: true, message: '邮箱不能为空', trigger: 'blur'}],

                }
            }
        },
        created: function () {
            this.loadData();
        },
        methods:{
            onSubmit() {
                this.currentPage = 1;
                this.loadData();
                this.formInline.memberName = ''
                this.formInline.carName = ''
                this.formInline.startTime = ''
                this.formInline.endTime = ''
            },loadData() {
                let _this = this;
                this.$http.post("/cs/order/queryOrderVo?pageNum=" + this.currentPage + "&pageSize=" + this.pageSize + "", this.formInline)
                    .then((response) => {
                        console.log(response.data);
                        let list = response.data.t.list;
                        _this.tableData = list
                        _this.total = response.data.t.total;
                    })
            },//分页 每页数量变化时处理
            handleSizeChange(val) {
                this.pageSize = val;
                this.currentPage = 1;
                this.loadData();
            },
            //分页 第几页变化时处理
            handleCurrentChange(val) {
                this.currentPage = val;
                this.loadData();
            },
            //还车按钮
            handleEdit(){},
            handleDelete(){}
        }
    }
</script>

<style scoped>

</style>